package com.metadata_system.ai.response;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.metadata_system.common.db.entity.MetadataEdge;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

@AllArgsConstructor
@NoArgsConstructor
@Builder
@Data
public class MetadataEdgeResponse {
    private Integer id;
    private Integer metadataId;
    private Integer metadataViewId;
    private Integer source;
    private Integer target;
    private Integer type;
    private String name;
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date createdTime;
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date updatedTime;

    public static MetadataEdgeResponse fromEntity(MetadataEdge entity) {
        return MetadataEdgeResponse.builder()
                .id(entity.getId())
                .metadataId(entity.getMetadataId())
                .metadataViewId(entity.getMetadataViewId())
                .source(entity.getSource())
                .target(entity.getTarget())
                .type(entity.getType())
                .name(entity.getName())
                .createdTime(entity.getCreatedTime())
                .updatedTime(entity.getUpdatedTime())
                .build();
    }

    public static List<MetadataEdgeResponse> fromEntity(List<MetadataEdge> list) {
        return list.stream().map(MetadataEdgeResponse::fromEntity).collect(Collectors.toList());
    }
}
